define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {  
                   data:'',
                   popup3:0,
                    remark:'',
                    refund_money:0
                };
            },
            el: '#pageEatInHallOrder',
            created: function() {
                this.fetchData();
            },
            methods: {
                fetchData: function() {
                    this.loadOrder();
                    
                } ,
                //  onShow:function(){
                //    this.loadOrder();
                // },
              
                 setData:function(arr){
                  for( var i in arr){
                     this[i] = arr[i];
                  }
                },

                loadOrder(reload = 0) {
                  var that = this;                  
                  app.get("apiv2/order/find", {
                    order_sn: this.$route.params.order_sn
                  }, function (res) {
                    that.loading = 0;
                    if (res.code != 200) {
                      app.alert(res.msg);
                      return;
                    }
                    that.data= res.data;
                     
                  });
                }, 
                //出餐中
            eat_in_hall_receiving(order_sn) {
              // var order_sn = $(e.target).attr("order_sn");
              // var shop_id = $(e.target).attr("shop_id");
              var that = this;
              app.get('mall/eat_in_hall_order/receiving', {
                order_sn: order_sn
              }, function (data) {
                if (data.code ==200) {
                 app.alert("操作成功");
                  that.loadOrder(1);
                } else {
                  app.alert(data.msg);
                }
              });
            },
             //出餐完成
            eat_in_hall_complete(order_sn) {
              
              var that = this;
              app.get('mall/eat_in_hall_order/complete', {
                order_sn: order_sn
              }, function (data) {
                if (data.code ==200) {
                  app.alert('操作成功');
                  that.loadOrder(1);
                } else {
                  app.alert(data.msg);
                }
              });
            },

            //取消 退款
               eat_in_hall_cancel: function () {
                var that = this;
                that.setData({
                  loading: 1,
                  disabled: 1
                });
                // if (!this.remark){
                //   app.alert('请输入备注!');
                //   return ;
                // }
                // if (!this.refund_money ) {
                //   app.alert('请输入退回金额!');
                //   return;
                // }
                app.get('mall/eat_in_hall_order/cancel', {
                  order_sn: this.order_sn,
                  refund_desc: this.remark,
                  refund_money: this.refund_money
                //  method: 'POST',
                }, function (data) {
                  if (data.code == 200) {
                    app.alert('操作成功');
                    that.hide_refund_money();
                    that.loadOrder(1);
                  } else {
                    app.alert(data.msg);
                    that.setData({
                      loading: 0,
                      disabled: 0
                    });
                  }
                });
              },
              show_refund_money: function (e) {
              var order_sn = $(e.target).attr("order_sn");
             
              var refund_money = $(e.target).attr("refund_money");
              var paystatus = $(e.target).attr("paystatus");
              this.setData({
                  order_sn: order_sn,
                  refund_money: refund_money
               });
              if(refund_money>0 && paystatus ==1){
                this.setData({
                  popup3: 1
               });
              }else{
                this.eat_in_hall_cancel();
              }
              
            },
             hide_refund_money:function(){
              this.popup3=0;
            }
 
            }

        }).$mount('#app');
    };
    module.exports = controller;
});
